package junit;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.List;

/**
 * JunitParm..
 *
 * @author Lizhong
 * @date 2019/5/7
 */
@RunWith(Parameterized.class)
public class JunitParameterized {
    private int expect;

    private int first;
    private int second;

    /**
     * 构造器不能少
     * @param expected
     * @param firstNumber
     * @param secondNumber
     */
    public JunitParameterized(int expected, int firstNumber, int secondNumber) {
        this.expect = expected;
        this.first = firstNumber;
        this.second = secondNumber;
    }

    /**
     * static方法返回Iterator可迭代对象
     * @return
     */
    @Parameterized.Parameters
    public static List<Integer[]> parameter() {
        return Arrays.asList(new Integer[][]{{3, 1, 2}, {5, 2, 3}, {7, 3, 4}, {9, 4, 5},{4,1,4}});
    }

    @Test
    public void test() {
        String format = "Using parameters: expect=%d, first=%d, second=%d";
        System.out.println(String.format(format, expect, first, second));
        int plus = plus(first, second);
        Assert.assertEquals(expect,plus);
    }
    @Test
    public void testPrint() {
        String format = "Print ----------: expect=%d, first=%d, second=%d";
        System.out.println(String.format(format, expect, first, second));
    }
    private int plus(int first, int second) {
        return first + second;
    }

}
